#ifndef VEC2D__
#define VEC2D__



#include <string>
#include <cmath>

constexpr double kMathEpsilon = 1e-10;

class Vec2d {
public:
  constexpr Vec2d(const double x, const double y) noexcept : x_(x), y_(y) {}
  constexpr Vec2d() noexcept : Vec2d(0, 0) {}

  //! Creates a unit-vector with a given angle to the positive x semi-axis
  static Vec2d CreateUnitVec2d(const double angle) {return Vec2d(std::cos(angle), std::sin(angle));}
  double x() const { return x_; }
  double y() const { return y_; }
  void set_x(const double x) { x_ = x; }
  void set_y(const double y) { y_ = y; }
  double Length() const {return std::hypot(x_, y_);}
  double LengthSquare() const {return x_ * x_ + y_ * y_;}
  // 与x轴的夹角
  double Angle() const {return std::atan2(y_, x_);}
  void Normalize();
  double DistanceTo(const Vec2d &other) const {return std::hypot(x_ - other.x_, y_ - other.y_);}
  double DistanceSquareTo(const Vec2d &other) const;
  double CrossProd(const Vec2d &other) const {return x_ * other.y() - y_ * other.x();}
  double InnerProd(const Vec2d &other) const {return x_ * other.x() + y_ * other.y();}
  //! rotate the vector by angle.
  Vec2d rotate(const double angle) const;
  //! rotate the vector itself by angle.
  void SelfRotate(const double angle);
  Vec2d operator+(const Vec2d &other) const;
  Vec2d operator-(const Vec2d &other) const;
  Vec2d operator*(const double ratio) const;
  Vec2d operator/(const double ratio) const;
  Vec2d &operator+=(const Vec2d &other);
  Vec2d &operator-=(const Vec2d &other);
  Vec2d &operator*=(const double ratio);
  Vec2d &operator/=(const double ratio);
  bool operator==(const Vec2d &other) const;

protected:
  double x_ = 0.0;
  double y_ = 0.0;
};




#endif //